<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
	template="/templates/template.xhtml" xmlns:eq="http://www.equus.com.br/facelets/">

	<f:metadata>
		<f:event type="preRenderView" listener="#{movimentacaoBean.verificarAcesso}" />
	</f:metadata>

	<ui:define name="body">
		<h:form id="form" prependId="false">
			<h:panelGrid id="tagOs" width="100%">
				<eq:animal animal="#{movimentacaoBean.animal}" />
			</h:panelGrid>
			<p:fieldset legend="#{movimentacaoBean.qualifiedName}" id="fieldPrincipal">
				<p:tab title="Movimentação do Animal" id="tabMovimentacao">
					<h:panelGrid columns="4" id="panelMovimentacao" columnClasses="coluna15,coluna40,coluna20,coluna35" width="100%">

						<h:outputLabel value="Situação:" styleClass="icoObrigatorio" />
						<p:selectOneMenu id="idSituacao" effect="fade" style="width:300px;" value="#{movimentacaoBean.idSituacao}"
							requiredMessage="#{medicaoAnimalBean.requiredMessage}" required="true">
							<f:selectItem itemLabel="Selecione" itemValue="" />
							<f:selectItems value="#{movimentacaoBean.listaSituacao}" />
						</p:selectOneMenu>
						<p:message for="idSituacao" />
						<h:outputText value=" " />


						<h:outputText value="Data:" styleClass="icoObrigatorio" />
						<h:panelGrid columns="2" cellpadding="0" cellspacing="0">
							<p:calendar locale="pt" pattern="dd/MM/yyyy" id="dtInicio" navigator="true" maxlength="10" size="15"
								readOnlyInputText="true" value="${movimentacaoBean.model.dtAlteracao}" mode="popup" showOn="button"
								requiredMessage="#{movimentacaoBean.requiredMessage}" required="true" />
							<p:commandLink process="@this" title="Limpar" update="dtInicio">
								<h:graphicImage name="icone-limpar.png" library="design/imagem" />
								<f:setPropertyActionListener target="${movimentacaoBean.model.dtAlteracao}" value="" />
							</p:commandLink>
						</h:panelGrid>
						<p:message for="dtInicio" />
						<h:outputText value=" " />

						<h:outputLabel value="Observação:" />
						<p:inputTextarea autoResize="false" value="#{movimentacaoBean.model.observacao}" id="obs" cols="50" rows="5" />
				 </h:panelGrid>
					<br />
					<p:toolbar>
						<p:toolbarGroup align="left">
							<p:commandButton value="Voltar" immediate="true" ajax="false" action="pesquisarAnimal.jsf" />
							<p:commandButton value="Limpar" immediate="true" ajax="false" action="#{movimentacaoBean.limparTela}" />
							<p:commandButton rendered="#{p:ifGranted('ROLE_MOVIMENTACAO_SALVAR')}" value="Salvar" ajax="true" process="@form"
								update="@form" action="#{movimentacaoBean.save}" />
						</p:toolbarGroup>
					</p:toolbar>
					<br />
					<p:dataTable var="lista" id="listaMovimentacao" emptyMessage="#{movimentacaoBean.emptyMessage}"
						update="listaMovimentacao" rowsPerPageTemplate="#{movimentacaoBean.paginacao}" styleClass="coluna100"
						value="#{movimentacaoBean.lazyDataModel}" paginator="true" rows="5"
						rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'linhaImpar' : 'linhaPar'}" rowIndexVar="rowIx">

						<p:column headerText="Situação" style="width:30%">
							<h:outputLabel value="#{lista.situacao.descricao}" />
						</p:column>

						<p:column headerText="Observação" style="width:40%">
							<h:outputLabel value="#{lista.observacao}" />
						</p:column>

						<p:column headerText="Data" sortBy="#{lista.dtAlteracao}" style="width:20%">
							<h:outputLabel value="#{lista.dtAlteracao}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputLabel>
						</p:column>

						<p:column headerText="Ação" style="width:10%;text-align:center;">

							<p:commandLink rendered="#{p:ifGranted('ROLE_MOVIMENTACAO_EXCLUIR')}" title="Excluir" process="@this"
								oncomplete="confirmationMovimentacao.show()">
								<h:graphicImage library="design/imagem" name="icone-excluir.png" />
								<f:setPropertyActionListener target="#{movimentacaoBean.model}" value="#{lista}" />
							</p:commandLink>
						</p:column>
					</p:dataTable>
					<p:confirmDialog appendToBody="true" message="Confirma a Exclusão" header="Exclusão" severity="alert"
						widgetVar="confirmationMovimentacao">
						<h:panelGrid columns="2">
							<p:commandButton value="Sim" update="listaMovimentacao" oncomplete="confirmationMovimentacao.hide()"
								actionListener="#{movimentacaoBean.delete}" immediate="true" />
							<p:commandButton value="Não" onclick="confirmationMovimentacao.hide()" />
						</h:panelGrid>
					</p:confirmDialog>

				</p:tab>
			</p:fieldset>
		</h:form>
	</ui:define>
</ui:composition>